package data;

import java.sql.*;
import java.util.*;
import utils.Transacao;

public class AdministradorCobraPacienteData {

  public void incluir(AdministradorCobraPacienteDO adm, Transacao tr) throws Exception {
     Connection con = tr.obterConexao();
     String sql = "insert into AdministradorCobraPaciente (idPaciente, idFuncionario, valor, dataVencimento, statusCobranca, infoCobranca) values (?, ?, ?, ?, ?, ?)";
     PreparedStatement ps = con.prepareStatement(sql);
     ps.setInt(1, adm.getIdPaciente());
     ps.setInt(2, adm.getIdFuncionario());
     ps.setString(3, adm.getValor());
     ps.setString(4, adm.getDate());
     ps.setString(5, adm.getStatusCobranca());
     ps.setString(6, adm.getInfoCobranca());
     int result = ps.executeUpdate();
  }

  public void excluir(AdministradorCobraPacienteDO adm, Transacao tr) throws Exception {
     excluir(adm.getIdFuncionario(), tr);
     excluir(adm.getIdPaciente(), tr);
  } // excluir

  public void excluir (int idobj, Transacao tr) throws Exception {
  } // excluir 

  public void atualizar(AdministradorCobraPacienteDO adm, Transacao tr) throws Exception {
     Connection con = tr.obterConexao();
     String sql = "update AdministradorCobraPaciente set Paciente_idPaciente=?, Funcionario_idFuncionario=?, valor=?, dataVencimento=?, statusCobranca=?, infoCobranca=? where id=?";
     PreparedStatement ps = con.prepareStatement(sql);
     ps.setInt(1, adm.getIdPaciente());
     ps.setInt(2, adm.getIdFuncionario());
     ps.setString(3, adm.getValor());
     ps.setString(4, adm.getDate());
     ps.setString(5, adm.getStatusCobranca());
     ps.setString(6, adm.getInfoCobranca());
     int result = ps.executeUpdate();
  } // atualizar
  
  public void atualizarStatus(AdministradorCobraPacienteDO adm, Transacao tr) throws Exception {
  Connection con = tr.obterConexao();
     String sql = "update AdministradorCobraPaciente set statusCobranca=? where Paciente_idPaciente=?";
     PreparedStatement ps = con.prepareStatement(sql);
     ps.setString(1, adm.getStatusCobranca());
     int result = ps.executeUpdate();
  } // atualizarStatus
  
  public AdministradorCobraPacienteDO buscar(int idobj, Transacao tr) throws Exception {
     Connection con = tr.obterConexao();
     String sql = "select * from AdministradorCobraPaciente where  Paciente_idPaciente=?";
     PreparedStatement ps = con.prepareStatement(sql);
     ps.setInt(1, idobj);
     ResultSet rs = ps.executeQuery();
     rs.next();
     AdministradorCobraPacienteDO adm = new AdministradorCobraPacienteDO();
     adm.setIdPaciente (rs.getInt("Paciente_idPaciente"));
     adm.setIdFuncionario (rs.getInt("Funcionario_idFuncionario"));
     adm.setValor(rs.getString("valor"));
     //adm.setDate(rs.getString("dataVencimento"));
     adm.setStatusCobranca(rs.getString("statusCobranca"));
     adm.setInfoCobranca(rs.getString("informacaoCobranca"));
     return adm;
  } // buscar

  public Vector pesquisarPorNome(String nome, Transacao tr) throws Exception {
     Connection con = tr.obterConexao();
     String sql = "select * from AdministradorCobraPaciente where nome like ?";
     PreparedStatement ps = con.prepareStatement(sql);
     ps.setString(1, nome);
     ResultSet rs = ps.executeQuery();
     System.out.println("query executada");
     Vector adms = new Vector();
     while (rs.next()) {
        AdministradorCobraPacienteDO c = new AdministradorCobraPacienteDO();
        c.setIdPaciente (rs.getInt("idPaciente"));
        System.out.println(" got " + c.getIdPaciente());
        adms.add(c);
     }
     return adms;
  } // pesquisarPorNome

} // ContatoData